#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>

#include <iostream>
#include "detail/stack_array.hpp"

template class fixed_size_list<int,5>;

struct destr_tracker
{
	static int count_;
	destr_tracker(){count_++;}
	destr_tracker(const destr_tracker&){count_++;}
	~destr_tracker(){count_--;}
};
int destr_tracker::count_=0;

BOOST_AUTO_TEST_CASE(stack_array_test_1)
{
	fixed_size_list<int,5> lst;
	lst.push_front(1);
	lst.push_front(2);
	lst.push_front(3);

	BOOST_CHECK(lst.size()==3);
	BOOST_CHECK(lst[0]==3 && lst[1]==2 && lst[2]==1);
}

BOOST_AUTO_TEST_CASE(stack_array_test_2)
{
	fixed_size_list<int,5> lst;
	lst.push_front(1);
	lst.push_front(2);
	lst.push_front(3);

	lst.pop_front();
	lst.push_back(4);

	BOOST_CHECK(lst.size()==3);
	BOOST_CHECK(lst[0]==2 && lst[1]==1 && lst[2]==4);
}

BOOST_AUTO_TEST_CASE(stack_array_test_3)
{
	fixed_size_list<int,5> lst;
	lst.push_back(1);
	lst.push_front(0);
	lst.push_back(2);
	lst.pop_back();

	BOOST_CHECK(lst.size()==2);
	BOOST_CHECK(lst[0]==0 && lst[1]==1);
}

BOOST_AUTO_TEST_CASE(stack_array_test_4)
{
	fixed_size_list<int,5> lst;
	lst.push_back(1);
	lst.push_back(2);
	lst.push_back(3);
	lst.push_back(4);
	lst.push_back(5);

	try
	{
		lst.push_back(6);
		BOOST_CHECK(0);
	}
	catch(const std::out_of_range &)
	{
	}
}

BOOST_AUTO_TEST_CASE(stack_array_test_5)
{
	std::cerr<<"5"<<std::endl;

	{
		fixed_size_list<destr_tracker,2> tracker;
		tracker.push_back(destr_tracker());
		tracker.push_back(destr_tracker());
	}
	BOOST_CHECK(destr_tracker::count_==0);
}

BOOST_AUTO_TEST_CASE(stack_array_test_6)
{	
	int arr[5]={1,2,3,4,5};
	fixed_size_list<int,10> tracker(arr,arr+5);
	BOOST_CHECK(tracker.size()==5);
	for(int f=0;f<5;f++)
		BOOST_CHECK(tracker[f]==arr[f]);	
}
